# _*_ coding:utf-8 _*_
# @Time  : 2023.03.17
# @Author: zizlee
import socket  # 导入 socket 模块
import time
import threading

s = socket.socket()  # 创建 socket 对象

s.connect(('127.0.0.1', 12222))

is_close = False


def receive_thread():
    while 1:
        recv = s.recv(1024)
        print(recv.decode('utf8'))
        if recv == 'close':
            break
    global is_close
    is_close = True
    s.close()


def send_thread():
    while 1:
        s.send('我是客户端1'.encode('utf8'))
        if is_close:
            break
        time.sleep(1)
        print('发送')


t = threading.Thread(target=receive_thread, daemon=True)
t2 = threading.Thread(target=send_thread, daemon=True)
t.start()
t2.start()
while True:
    # print('启动完成')
    time.sleep(1)
